package com.shen;

import java.io.*;
import java.util.Scanner;

/**
 * Author:shen
 * CreateDate:2020/6/3.
 * Function:
 */
public class demo04 {
    static Scanner scanner=new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("请输入一个文件名：");
        String fileName=scanner.nextLine();
        File file=new File("E:/",fileName);
        if(file.exists()&&file.isFile()){
            FileReader fileInputStream=null;
            try {
                fileInputStream=new FileReader(file);

                int len;
                while ((len=fileInputStream.read())!=-1){
                    System.out.print((char) len);
                }

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    if(fileInputStream!=null){
                        fileInputStream.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }else{
            System.out.println("请输入一个正确的文件！");
        }

    }



}
